<!--
  Copyright (c) 2017-present, Facebook, Inc.
  All rights reserved.

  This source code is licensed under the license found in the
  LICENSE file in the root directory of this source tree.
-->

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="apple-mobile-web-app-capable" content="yes"/>
  <meta name="full-screen" content="yes"/>
  <meta name="screen-orientation" content="portrait"/>
  <meta name="viewport" content="user-scalable=no"/>
  <link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <!-- build:js -->
  <script src="https://connect.facebook.net/en_US/fbinstant.6.2.js"></script>
  <!-- endbuild -->
  <script src="js/display.js"></script>
  <script type="text/javascript">
    const display = window.Display;

    const OTHER_APP_ID = '<YOUR OTHER APP ID HERE>';
    const CUSTOM_DATA = { 'custom_data': 42 };

    window.onload = function() {
      $('#switch-section').hide();
      FBInstant.initializeAsync()
      .then(FBInstant.startGameAsync)
      .then(onStart);
    };

    function onStart() {
      // Print any entry point data we might have
      var entryPointData = FBInstant.getEntryPointData();
      if (entryPointData) {
        $('#entry-point-data').html(JSON.stringify(entryPointData));
      }

      // Check if this session supports Game Switching
      var supportedAPIs = FBInstant.getSupportedAPIs();
      if (supportedAPIs.includes('switchGameAsync')) {
        $('#switch-section').show();
      } else {
        display.error('This client version does not support Game Switching.');
      }
    }

    function switchToMyOtherGame() {
      FBInstant.switchGameAsync(OTHER_APP_ID, CUSTOM_DATA)
      .catch(function(error) {
        display.error(error.message);
      });
    }
  </script>

  <header>
    <h1>Instant Games Demos</h1>
    <h2>Switching Between Games</h2>
  </header>

  <section>
    <h3>Entry Point Data</h3>
    <pre id="entry-point-data" class="output">(empty)</pre>
  </section>

  <section id="switch-section">
    <h3>Switch Games</h3>
    <p>Press the button below to switch to the app ID specified in this file.</p>
    <input type="button"
      id="btn-switch"
      onclick="switchToMyOtherGame();"
      value="Switch to Another Game"/>
  </section>

  <section>
    <p id="display-message" class="output"></p>
    <p id="display-success" class="success"></p>
    <p id="display-error" class="error"></p>
  </section>
</body>
</html>
